#include<iostream>
#include<string>
#include<vector>
#include<unordered_map>
#include<utility>
using namespace std;

//1576.替换所有的问号
string modifyString(string s){
    for (int i = 0; i < s.size();i++){
        if(s[i]=='?'){
            for (char ch = 'a'; ch < 'z';ch++){
                if((i==0||s[i-1]!=ch)&&(i==s.size()-1||s[i+1]!=ch)){
                    s[i] = ch;
                    break;
                }
            }
        }
    }

    return s;
}

//495.提莫攻击
int findPoisonedDuration(vector<int>& timeSeries, int duration){
    int ret = 0;
    for (int i = 1; i < timeSeries.size();i++){
        int x = timeSeries[i] - timeSeries[i - 1];
        //如果前后差大于等于中毒时间，直接加上中毒时间
        if(x>=duration){
            ret += duration;
        }
        //前后差小于，加上差值
        else{
            ret += x;
        }
    }

    //最后要加上最后一次的中毒时间
    return ret + duration;
}

//6.N字形转换
string convert(string s, int numRows){
    if(numRows==1){
        return s;
    }
    string ret;
    int k = 0;
    int d = 2 * numRows - 2;
    //第一行
    while(k*d<s.size()){
        ret += s[0 + k * d];
        k++;
    }

    //中间行
    int i = 1;
    while(i<=numRows-2){
        k = 0;
        int j = d - i;
        while(i+k*d<s.size()||j+k*d<s.size()){
            ret += s[i + k * d];
            if(j+k*d<s.size()){
                ret += s[j + k * d];
            }
            k++;
        }
        i++;
    }

    //最后一行
    k = 0;
    while(numRows-1+k*d<s.size()){
        ret += s[numRows - 1 + k * d];
        k++;
    }

    return ret;
}

//38.外观数列
string countAndSay(int n){
    string ret = "1";
    string tmp;

    //循环次数是n-1次
    for (int i = 1; i < n;i++){
        //双指针找到相同的子串
        for (int left = 0, right = 0; right < ret.size();){
            while(right<ret.size()&&ret[left]==ret[right]){
                right++;
            }
            //先插入相同字串的长度
            tmp += to_string(right - left);
            //再插入数字
            tmp += ret[left];
            //更新左指针
            left = right;
        }
        ret = tmp;
        tmp.clear();
    }
    return ret;
}

//1149.数青蛙
int minNumberOfFrogs(string croakOfFrogs){
    string s="croak";
    unordered_map<char, pair<int,int>> hash;
    
    for (int i = 0; i < s.size();i++){
        if(i==0){
            hash[s[i]].first = s.size() - 1;
        }
        else{
            hash[s[i]].first = i - 1;
        }
    }

    for (auto ch : croakOfFrogs){
        if(hash[s[hash[ch].first]].second){
            hash[s[hash[ch].first]].second--;
            hash[ch].second++;
        }
        else{
            if(ch=='c'){
                hash[ch].second++;
            }
            else{
                return -1;
            }
        }
    }

    for (int i = 0;i<s.size()-1;i++){
        if(hash[s[i]].second){
            return -1;
        }
    }

    return hash[s[s.size() - 1]].second;
}

int main(){
    int ret = minNumberOfFrogs("croakcroak");
    cout << ret;
    return 0;
}